// services/api.js
import axios from 'axios';

const instance = axios.create({
  baseURL: 'http://localhost:8080/api',
  timeout: 5000
});

// 请求拦截器（自动添加Token）
instance.interceptors.request.use(config => {
  const token = localStorage.getItem('token');
  if (token) config.headers.Authorization = `Bearer ${token}`;
  return config;
});

// 响应拦截器（统一错误处理）
instance.interceptors.response.use(
  response => response.data,
  error => Promise.reject(error.response?.data?.message || '请求失败')
);

export default instance;

